all:
	$(MAKE) linux

dist:
	+$(MAKE) -C src/libtd_bdd dist
	mv src/libtd_bdd/libtd_bdd.so src/libtd_bdd/browser/
	+$(MAKE) -C src/libtd_bdd/browser
	mv src/libtd_bdd/browser/libtd_bdd.so .
	mv src/libtd_bdd/browser/td_browser .
	cp src/libtd_bdd/browser/td_browser.sh .
	cp libtd_bdd.so src/
	+$(MAKE) -C src CC='dist' flag='-rdynamic -ldl'
	+$(MAKE) -C src/modules CC='dist' flag='-fPIC' ext_mod='.so'
	mv src/modules/*.so modules/
	mv src/modules/decrypt_ip modules/

linux:
	$(MAKE) -C src/libtd_bdd linux
	mv src/libtd_bdd/libtd_bdd.so src/libtd_bdd/browser/
	$(MAKE) -C src/libtd_bdd/browser
	mv src/libtd_bdd/browser/libtd_bdd.so .
	mv src/libtd_bdd/browser/td_browser .
	cp src/libtd_bdd/browser/td_browser.sh .
	cp libtd_bdd.so src/
	$(MAKE) linux_kernel 
	$(MAKE) linux_modules
	mv src/modules/*.so modules/
	mv src/modules/decrypt_ip modules/

bsd:
	$(MAKE) -C src/libtd_bdd bsd
	mv src/libtd_bdd/libtd_bdd.so src/libtd_bdd/browser/
	$(MAKE) -C src/libtd_bdd/browser
	mv src/libtd_bdd/browser/libtd_bdd.so .
	mv src/libtd_bdd/browser/td_browser .
	cp src/libtd_bdd/browser/td_browser.sh .
	cp libtd_bdd.so src/
	$(MAKE) bsd_kernel
	$(MAKE) bsd_modules
	mv src/modules/*.so modules/
	mv src/modules/decrypt_ip modules/

solaris:
	$(MAKE) -C src/libtd_bdd solaris
	mv src/libtd_bdd/libtd_bdd.so src/libtd_bdd/browser/
	$(MAKE) -C src/libtd_bdd/browser
	mv src/libtd_bdd/browser/libtd_bdd.so .
	mv src/libtd_bdd/browser/td_browser .
	cp src/libtd_bdd/browser/td_browser.sh .
	cp libtd_bdd.so src/
	$(MAKE) solaris_kernel
	$(MAKE) solaris_modules
	mv src/modules/*.so modules/
	mv src/modules/decrypt_ip modules/


darwin:
	$(MAKE) -C src/libtd_bdd darwin
	mv src/libtd_bdd/libtd_bdd.dylib src/libtd_bdd/browser/
	$(MAKE) -C src/libtd_bdd/browser
	mv src/libtd_bdd/browser/libtd_bdd.dylib .
	mv src/libtd_bdd/browser/td_browser .
	cp src/libtd_bdd/browser/td_browser.sh .
	cp libtd_bdd.dylib src/
	$(MAKE) darwin_kernel
	$(MAKE) darwin_modules
	mv src/modules/*.so modules/
	mv src/modules/decrypt_ip modules/
	
win32:
	$(MAKE) -C src/libtd_bdd win32
	copy src\libtd_bdd\libtd_bdd.dll src\libtd_bdd\browser
	$(MAKE) -C src/libtd_bdd/browser win32
	copy src\libtd_bdd\browser\td_browser.exe .
	copy src\libtd_bdd\libtd_bdd.dll .
	copy libtd_bdd.dll src
	copy libtd_bdd.dll src\modules
	$(MAKE) win32_kernel
	$(MAKE) win32_modules
	$(MAKE) -C src/modules strip-win
	copy src\modules\*.dll modules
	del src\modules\*.dll
	copy src\modules\decrypt_ip.exe modules
	del src\modules\decrypt_ip.exe
		
cross-win:
	$(MAKE) -C src/libtd_bdd cross-win
	mv src/libtd_bdd/libtd_bdd.dll src/libtd_bdd/browser/
	$(MAKE) -C src/libtd_bdd/browser cross-win
	mv src/libtd_bdd/browser/libtd_bdd.dll .
	mv src/libtd_bdd/browser/td_browser.exe .
	cp libtd_bdd.dll src/
	cp libtd_bdd.dll src/modules/
	$(MAKE) cross_kernel
	$(MAKE) cross_modules
	#$(MAKE) -C src/modules strip-cross
	mv src/modules/*.dll modules/
	mv src/modules/decrypt_ip.exe modules/
	

linux_kernel:
	$(MAKE) -C src CC='gcc -g' flag='-Wl,--export-dynamic -ldl -L. -ltd_bdd'

linux_modules:
	$(MAKE) -C src/modules CC='gcc' CXX='g++' flag='-g -O3 -fPIC' ext_mod='.so' link_flag='-shared -Wl' INC_MYSQL='`mysql_config --include`' LIB_MYSQL='`mysql_config --libs`'


bsd_kernel:
	$(MAKE) -C src CC='gcc -I/usr/local/include' flag='-Wl,--export-dynamic -L. -ltd_bdd -L/usr/local/lib -liconv'
	
bsd_modules:
	$(MAKE) -C src/modules CC='gcc' CXX='g++' flag='-O3 -fPIC' ext_mod='.so' link_flag='-shared -Wl' INC_MYSQL='`mysql_config --include`' LIB_MYSQL='`mysql_config --libs`' cxx_flag='-lstdc++'


solaris_kernel:
	$(MAKE) -C src CC='gcc' flag='-Wl,--export-dynamic -ldl -lsocket -lnsl -L. -ltd_bdd'

solaris_modules:
	$(MAKE) -C src/modules CC='gcc' CXX='g++' flag='-O3 -fPIC' ext_mod='.so' link_flag='-shared -Wl' INC_MYSQL='`mysql_config --include`' LIB_MYSQL='`mysql_config --$


darwin_kernel:
	$(MAKE) -C src CC='gcc' flag='-L. -ltd_bdd -liconv'
	
darwin_modules:
	$(MAKE) -C src/modules CC='gcc' CXX='g++' flag='-O3' ext_mod='.so' link_flag='-bundle -flat_namespace -undefined suppress' INC_MYSQL='`mysql_config --include`' LIB_MYSQL='`mysql_config --libs`'


win32_kernel:
	windres -i src/icone/icone.rc -o src/icone.o
	$(MAKE) -C src CC='gcc' flag='-lwsock32 -L. -ltd_bdd' ext_bin='.exe' icone='icone.o'
	strip --strip-all NewSyndrome.exe

win32_modules:
	$(MAKE) -C src/modules CC='gcc' CXX='g++' flag='-O3' ext_mod='.dll' ext_bin='.exe' sock_flag='-lwsock32' td_flag='-L. -ltd_bdd' link_flag='-shared -Wl' INC_MYSQL='-I../../mysql/' LIB_MYSQL='-L../../mysql/ -lmysql'


cross_kernel:
	cross-windres -i src/icone/icone.rc -o src/icone.o
	$(MAKE) -C src CC='cross-gcc' flag='-lwsock32 -L. -ltd_bdd' ext_bin='.exe' icone='icone.o'
#	cross-strip --strip-all NewSyndrome.exe
	
cross_modules:
	$(MAKE) -C src/modules CC='cross-gcc' CXX='cross-g++' flag='-O3' ext_mod='.dll' ext_bin='.exe' sock_flag='-lwsock32' td_flag='-L. -ltd_bdd' link_flag='-shared -Wl' INC_MYSQL='-I../../mysql/' LIB_MYSQL='-L../../mysql/ -lmysql'

clean:
	rm -rf src/libtd_bdd/browser/*.o
	rm -rf src/libtd_bdd/browser/*.c~
	rm -rf src/libtd_bdd/browser/*.h~
	rm -rf src/libtd_bdd/browser/*.dll
	rm -rf src/libtd_bdd/browser/*.so
	rm -rf src/libtd_bdd/*.o
	rm -rf src/libtd_bdd/*.c~
	rm -rf src/libtd_bdd/*.h~
	rm -rf src/libtd_bdd/*.dll
	rm -rf src/libtd_bdd/*.so
	rm -rf src/modules/*.o
	rm -rf src/modules/*.c~
	rm -rf src/modules/*.h~
	rm -rf src/modules/*.so
	rm -rf src/modules/*.dll
	rm -rf src/*.o
	rm -rf src/*.c~
	rm -rf src/*.h~
	rm -rf src/*.so
	rm -rf src/*.dll
	rm -rf *.log
